package com.ms.log.logger;

import com.ms.log.appender.Appender;
import com.ms.log.event.LogEvent;
import com.ms.log.level.Level;

/**
 * @author zdh
 * 默认日志输出者，只输出 info 以上日志，且只输出到控制台
 */
public class DefaultLogger extends AbstractLogger{

    public DefaultLogger(String loggedName){
       super(loggedName);
    }

    public DefaultLogger(Level level,Appender appender){
        super(appender,level);
    }


    public DefaultLogger(String loggedName,Appender appender){
        super(loggedName,appender);
    }
    public DefaultLogger(String loggedName,Appender appender,Level level){
        super(loggedName,appender,level);
    }

    @Override
    public void append(Level level, String msg){
        LogEvent e = new LogEvent(level, msg,getLoggedName());
        e.setThreadId(Thread.currentThread().getId());
        e.setThreadName(Thread.currentThread().getName());
        e.setTimestamp(System.currentTimeMillis());
        //配置的 super.level 日志输出级别
        //目标的日志级别大于等于当前级别才可以输出
        if(level.getValue() >= this.getLevel().getValue()){
            append.append(e);
        }
    }


}
